<template>
  <div>
    <p>名称: <input type="text" v-model="form.name"></p>
    <p>用户名: <input type="text" v-model="form.username"></p>
    <p>密码: <input type="password" v-model="form.password"></p>
    <p>班级: <select name="" id="" v-model="form.cla">
      <option :value="i.id" v-for="i in clalist">{{i.name}}</option>
    </select></p>
    <p>
      <button @click="register">注册</button>
    </p>
  </div>
</template>

<script>
export default {
  data() {
    return {
      clalist: [],
      form: {}
    }
  },
  methods: {
    getClalist() {
      this.axios.get('showCourse/')
        .then(res => {
          this.clalist = res.data.list
        })
    },
    register(){
      this.axios.post('reg/',this.form)
      .then(res=>{
        if (res.data.code==200){
          localStorage.setItem('id',res.data.id)
          localStorage.setItem('name',res.data.name)
          this.$router.push({'path':'/stu'})
        }
      })
    }
  },
  mounted() {
    this.getClalist()
  }
}
</script>

<style scoped>

</style>
